package com.wkq.move.module.main.ui.adapter

import android.app.Activity
import android.content.Context
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.wkq.lib_base.adapter.KtDataBindingAdapter
import com.wkq.lib_base.adapter.KtDataBindingViewHolder
import com.wkq.move.R
import com.wkq.move.databinding.ItemMoveDownBinding
import com.wkq.move.utlis.DownUtil.openXunLei
import com.wkq.net.model.MoveInfo

/**
 *
 * 作者:吴奎庆
 *
 * 时间:2020/5/17
 *
 * 用途:
 */


class MoveDownAdapter(context: Context, layoutId: Int) :
    KtDataBindingAdapter<MoveInfo>(context, layoutId) {

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        super.onBindViewHolder(holder, position)
        var ktHolder: KtDataBindingViewHolder = holder as KtDataBindingViewHolder
        var binding = ktHolder.getBinding() as ItemMoveDownBinding
        binding.data = getItem(position)

        if (viewClickListener != null) {
            binding.root.setOnClickListener {
                viewClickListener!!.onViewClick(binding.root, getItem(position))
            }
        }

        var madapter = MoveDownImgAdapter(mContext, R.layout.item_down_bt)
        binding.rvBt.layoutManager =
            LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false);
        binding.rvBt.adapter = madapter
        madapter.addItems(getItem(position)?.moveDownBt)

        madapter.setOnViewClickListener(object : OnAdapterViewClickListener<MoveInfo.DownBTInfo> {
            override fun onViewClick(v: View?, program: MoveInfo.DownBTInfo?) {
                openXunLei(
                    (mContext as Activity),
                    program?.getHref()
                )
            }

        })
    }
}